<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- 引入vue2的js文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.9/vue.js"></script>
    <style>
        #app {
            width: 500px;
            height: 500px;
            margin: 50px auto;
            display: flex;
            align-items: center;
            flex-direction: column;
        }

        p {
            width: 300px;
            height: 200px;
            line-height: 200px;
            text-align: center;
            border: 1px solid #000;
        }

        button {
            width: 100px;
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <div id="app">
        <p ref="pRef">{{what}}</p>
        <button @click="upd">V50获取答案</button>
    </div>

    <script>
        new Vue({
            el: '#app',
            data: {
                what: '今晚吃什么?',
                list: ['麻辣烫', '馄饨', '常德牛肉粉', '塔斯汀', '农家记']
            },
            methods: {
                upd() {
                    this.what = this.list[Math.floor(Math.random() * (this.list.length))]
                }
            },
            beforeCreate() {
                console.log('实例创建之前', this);
            },
            created() {
                console.log('实例创建完成', this);
            },
            beforeMount() {
                console.log('实例挂载之前', this.$refs.pRef);
            },
            mounted() {
                console.log('实例挂载完成', this.$refs.pRef);
            },
            beforeUpdate() {
                console.log('数据更新之前', this.$refs.pRef.innerText);
            },
            updated() {
                console.log('数据更新完成', this.$refs.pRef.innerText);
            },
        })
    </script>
</body>

</html>